/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is KazeOS Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2010
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/

package evisio.states.core 
{
    import evisio.states.State;

    import vegas.display.Background;
    import vegas.ioc.factory.ObjectFactory;

    import flash.events.Event;
    import flash.text.TextField;

    /**
     * The basic representation of a State object.
     */
    public class CoreState extends Background implements State
    {
        
        /**
         * Creates a new CoreState instance.
         */
        public function CoreState()
        {
            super() ;
        }        
        
        /**
         * The IoC factory reference of this screen.
         */
        public var factory:ObjectFactory ;  
        
        /**
         * The message field of the form.
         */
        public var field:TextField ; 
        
        /**
         * The locale object. This object contains all information in the localization of this state.
         */
        public var locale:Object ;                
        
        /**
         * The current message display in the state.
         */
        public function get message():String 
        {
            return field != null ? field.htmlText : "" ;        
        }
        
        /**
         * @private
         */
        public function set message( str:String ):void 
        {
            if ( field != null )
            {
                field.htmlText = str || "" ;        
            }
        }       
        
        /**
         * Close the state.
         */
        public function close():void
        {
        } 
        
        /**
         * Returns the i18n message of this state register in locale property.
         * @return the i18n message of this state register in locale property.
         */
        public function getMessage( id:String ):String
        {
            if ( locale != null )
            {
                if ( id in locale )
                {
                    return ( locale[id] as String ) || "" ;
                }
            }
            return "" ;
        }
        
        /**
         * Open the state.
         */        
        public function open():void
        {
            //
        }
        
        /**
         * Invoked to reset the state.
         */
        public function reset( e:Event = null ):void
        {
            if ( field != null )
            {
                field.text = "" ;
            }             
        }

    }
}
